import argparse
from config import Config
from argparse import ArgumentParser
import os.path
from scapy.all import *

def config_set():
	parser = ArgumentParser()
   
        parser.add_argument("-c", dest="filename", required=True, help="config file")
        args = parser.parse_args()
        f = file(args.filename)
        cfg = Config(f)
        dstip = cfg.dstip
        prot = cfg.prot
        dport = cfg.dport
        inter = cfg.inter
        timeout = cfg.timeout
	return dstip, prot, dport, inter, timeout

def packet_send():
	dstip, prot, dport1, interval, tout=config_set()
	#print type(dport1)
	dport2=list(dport1)
	#print dport2
	#dstip = str(dstip)
	if prot=='ICMP':
		ans,unans=sr(IP(dst=dstip)/ICMP(),inter=interval,retry=-2,timeout=tout)
	if prot=='TCP':
        	ans,unans=sr(IP(dst=dstip)/TCP(dport=dport2, flags="S"),inter=interval,retry=-2,timeout=tout)
        	
	if prot=='UDP':
		ans,unans=sr(IP(dst=dstip)/UDP(dport=dport2),inter=interval,retry=-2,timeout=tout)
	#ans.nsummary()
	#unans.nsummary()
packet_send()
